package com.qingmi.farmer.viewmodel;

import android.databinding.ObservableField;

import com.qingmi.farmer.data.DataSetting;
import com.qingmi.farmer.data.model.GoodsInfo;
import com.qingmi.farmer.data.model.GoodsOrder;
import com.wjjun.basemvpvm.viewmodel.BaseViewModel;

/**
 * 生资订单也叫买入订单
 * Created by 67535 on 2018/5/10.
 */
public class GoodsOrderItemViewModel extends BaseViewModel {

    public String id;

    public GoodsInfo goodsInfo;

    //供应商名字
    public final ObservableField<String> suppliersName = new ObservableField<>();

    //状态
    public final ObservableField<Integer> status = new ObservableField<>(0);

    //图标
    public final ObservableField<String> icon = new ObservableField<>();

    //商品名称
    public final ObservableField<String> goodsName = new ObservableField<>();

    //套餐或类型
    public final ObservableField<String> type = new ObservableField<>();

    //单价
    public final ObservableField<Double> price = new ObservableField<>();

    //旧的价格单价
    public final ObservableField<Double> oldPrice = new ObservableField<>();

    //总量
    public final ObservableField<Integer> count = new ObservableField<>();

    //旧的总量
    public final ObservableField<Integer> oldCount = new ObservableField<>();

    public final ObservableField<String> unit = new ObservableField<>();
    //已完成量
    public final ObservableField<Integer> alreadyCount = new ObservableField<>();

    //总价
    public final ObservableField<Double> totalPrice = new ObservableField<>();

    //运费
//    public final ObservableField<Double> freight = new ObservableField<>();

    //订单号
    public final ObservableField<String> orderId = new ObservableField<>();

    //下单时间
    public final ObservableField<Long> orderTime = new ObservableField<>();


    public GoodsOrderItemViewModel(GoodsOrder goodsOrder) {
        id = goodsOrder.getResponseGoodId();
        goodsInfo = goodsOrder.getGood();

        if (goodsOrder.getGood() != null) {
            goodsName.set(goodsOrder.getGood().getName());
            icon.set(goodsOrder.getGood().getPic());
            type.set(goodsOrder.getGood().getSpecificationPara());

            unit.set(goodsOrder.getGood().getUnit());

            if (goodsOrder.getGood().getSupplier() != null) {
                suppliersName.set(goodsOrder.getGood().getSupplier().getSupplierName());
            }
        }

        status.set(goodsOrder.getStatusId());
        alreadyCount.set(goodsOrder.getHasBuyNum());
        totalPrice.set(goodsOrder.getTotalMoney());
        orderId.set(goodsOrder.getOrderId());
        price.set(goodsOrder.getPrice());

        if (goodsOrder.getStatusId() == DataSetting.GOODS_ORDER_STATUS_PENDING_CHECK) { //待审核
            count.set(goodsOrder.getReserveNum());
            orderTime.set(goodsOrder.getBuyAt());
        } else if (goodsOrder.getStatusId() == DataSetting.GOODS_ORDER_STATUS_PENDING_CONFIRM) {// 待确认
            count.set(goodsOrder.getConfirmNum());
            oldCount.set(goodsOrder.getReserveNum());
            orderTime.set(goodsOrder.getApplyAt());
        } else {
            count.set(goodsOrder.getConfirmNum());
            orderTime.set(goodsOrder.getConfirmAt());
        }
    }
}
